// node 后端服务器
const userApi = require('./api');
const fs = require('fs');
const path = require('path');
const bodyParser = require('body-parser');
const express = require('express');
const app = express();

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
//跨域问题
app.all('*', function (req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "X-Requested-With");
  res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
  res.header("X-Powered-By", ' 3.2.1');
  res.header("Content-Type", "application/json;charset=utf-8");
  next();
});
// 服务开启后访问指定编译好的dist文件下的数据
app.use(express.static(path.resolve(__dirname, '../../dist')))
app.get('html', function (req, res) {
  const html = fs.readFileSync(path.resolve(__dirname, '../../dist/index.html'), 'utf-8')
  res.send(html)
})
//路由配置
const upload = require('./upload.js');
app.use('/upload', upload)
// 后端api路由
app.use('/', userApi);
// 监听端口
app.listen(8088);
console.log('success listen at port:8088......');